package com.googlecode.yoohoo.xmppcore.protocol.stanza.error;

import com.googlecode.yoohoo.utils.Constants;
import com.googlecode.yoohoo.xmppcore.protocol.translation.ITranslator;
import com.googlecode.yoohoo.xmppcore.protocol.translation.IXmlWriter;
import com.googlecode.yoohoo.xmppcore.protocol.translation.XmlWriter;


public class SimpleApplicationSpecificCondition implements ITranslator {
	protected String xmlLang;
	protected String desc;
	protected String definedCondition;
	protected String namespace;
	
	public SimpleApplicationSpecificCondition(String definedCondition, String namespace) {
		this(definedCondition, namespace, null);
	}
	
	public SimpleApplicationSpecificCondition(String definedCondition, String namespace, String desc) {
		this(definedCondition, namespace, desc, Constants.DEFAULT_CHARSET);
	}
	
	public SimpleApplicationSpecificCondition(String definedCondition, String namespace,
			String desc, String xmlLang) {
		this.definedCondition = definedCondition;
		this.namespace = namespace;
		this.desc = desc;
	}
	
	@Override
	public String toXml() {
		IXmlWriter writer = new XmlWriter();
		writer.writeStartElement(definedCondition);
		if (xmlLang != null) {
			writer.writeAttribute("xml:lang", xmlLang);
		}
		writer.writeNamespace(namespace);
		if (desc != null) {
			writer.writeCharacters(desc);
		}
		writer.writeEndElement();
		
		return writer.toXml();
	}
}
